package 网络编程;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class UrlDownload {
    public static void main(String[] args) throws IOException {
        URL url = new URL("https://m704.music.126.net/20231010104351/5bf5c634169fc51535c24c22f6aefe9b/jdyyaac/obj/w5rDlsOJwrLDjj7CmsOj/29478578409/ff40/73aa/c521/0e34730bb66ef2d5dc51bc9afd605945.m4a?authSecret=0000018b17613f4e19ce0aaba3960f0f");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        InputStream inputStream = connection.getInputStream();

        FileOutputStream outputStream = new FileOutputStream("a.mp3");

        byte[] buffer = new byte[1024];
        int len;
        while ((len = inputStream.read(buffer)) != -1) {
            outputStream.write(buffer, 0, len);
        }
        outputStream.close();
        inputStream.close();
        connection.disconnect();
    }
}
